package bean_factory

import (
	. "gitee.com/kristas/booting-go/framework/core/bean"
	"gitee.com/kristas/booting-go/framework/core/log"
)

func init() {
	processors = append(processors, new(beanNameAwareProcessor))
}

type beanNameAwareProcessor struct {
	Log log.Logger `wire:""`
}

func (b *beanNameAwareProcessor) Filter(bean Bean) bool {
	_, ok := bean.(NameAware)
	return ok
}

func (b *beanNameAwareProcessor) Do(bean Bean) error {
	aware := bean.(NameAware)
	beanName := GetBeanName(bean)
	aware.SetBeanName(beanName)
	b.Log.Trace(traceLog(bean, "SetBeanName()"))
	return nil
}

func (b *beanNameAwareProcessor) Order() int {
	return orderBeanNameAwareProcessor
}
